<template>
  <div>
    <!--面包屑导航区-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>参数列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片视图区-->
    <el-card>
      <!--警告区-->
      <el-alert title="注意：只允许为第三级分类设置相关参数" type="warning" :closable="false" show-icon></el-alert>
      <!--选择商品分类区-->
      <el-row class="cat_opt">
        <el-col>
          <span>选择商品分类：</span>
          <!--级联选择框-->
          <el-cascader
            expand-trigger="hover"
            :options="CateList"
            :props="cateProps"
            v-model="selectedKeys"
            @change="CateChange"
            clearable
          ></el-cascader>
        </el-col>
      </el-row>
      <!--tabs页签-->
      <el-tabs v-model="activeName" @tab-click="handleTabClick">
        <el-tab-pane label="动态参数" name="first">
          <el-button type="primary" size="mini" :disabled="isBtnDisabled">添加参数</el-button>
        </el-tab-pane>
        <el-tab-pane label="静态属性" name="静态属性">
          <el-button type="primary" size="mini" :disabled="isBtnDisabled">添加属性</el-button>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Params',
  data() {
    return {
      // 分类列表
      CateList: [],
      // 级联选择框
      cateProps: {
        value: 'cat_id',
        label: 'cat_name',
        children: 'children'
      },
      selectedKeys: [],
      // 激活页签名称
      activeName: 'first'
    }
  },
  created() {
    // 获取分类列表
    this.getCateList()
  },
  methods: {
    // 获取分类列表
    async getCateList() {
      const { data: res } = await this.$http.get('categories')
      if (res.meta.status !== 200) {
        return this.$message.error('获取分类失败')
      }
      this.CateList = res.data
    },
    // 级联选择框
    CateChange() {
      console.log(this.selectedKeys)
    },
    // tabs页签
    handleTabClick() {}
  },
  computed: {
    isBtnDisabled() {
      if (this.selectedKeys.length !== 1) {
        return true
      }
      return false
    }
  }
}
</script>

<style scoped>
.cat_opt {
  margin: 15px 0;
}
</style>
